package StudyCode.summary.mycollection;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class CreateConcurrentHashMap {
	public static final double FACTOR = 0.75;
	public static final int MIN_CAPACITY = 16;

	public static <K, V> Map<K, V> createConcurrentHashMap(int size) {
		return new ConcurrentHashMap<>(getSize(size));
	}

	public static int getSize(int size) {
		return getSize(size, true);
	}

	public static int getSize(int size, boolean useMinimum) {
		int s = (int) (size / FACTOR) + 1;

		if (useMinimum) {
			s = Math.max(MIN_CAPACITY, s);
		}
		return s;
	}
}
